﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Collections.ObjectModel;

namespace JHoelsch.DataClases.DataBase
{
    public class Car :  SerializableObject
    {
        public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Car));           
        public Car()
        {
            Tankquittungen = new ObservableCollection<TankQuittung>();
        }
        public string Name {
            get
            {
                return (string)GetValue(NameProperty); 
            }
            set
            {
                SetValue(NameProperty, value);
            }
        }
        public string Kennzeichen { get; set; }
        public string Fahrgestellnummer { get; set; }
        public int ErsteKmStand { get; set; }
        public int AktuellerKilometerstand{ get
            {
                if (this.Tankquittungen.Count > 0)
                {
                    return this.Tankquittungen.Max(obj => obj.KMStand);
                }
                else
                    return this.ErsteKmStand;
            } }
        [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, DataType = "date")]
        public DateTime KaufDatum { get; set; }
        public ObservableCollection<TankQuittung> Tankquittungen { get; set; } 
        public override string ToString()
        {
            return this.Name;
        }
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public double Durchschnittsverbrauch
        {
            set { Durchschnittsverbrauch = value; }
            get
            {
                if (this.Tankquittungen.Count > 0)
                {
                    int kilometer = this.Tankquittungen.Max(obj => obj.KMStand);
                    double liter = this.Tankquittungen.Sum(obj => obj.Liter);
                    return Math.Round(liter / AktuellerKilometerstand * 100, 2);
                }
                else
                    return 0.0;
            }
        }
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public Brush Color { get; set; }
        ~Car(){}
    }
}